package com.lkm.market2_0.steelyards;

import com.lkm.frame.module.ConditionConfige;
import com.lkm.frame.module.ModuleDelegate;
import com.lkm.frame.module.ModuleManager;
import com.lkm.frame.module.PermissionCondition;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m.steelyardstatus.SteelyardStatusManagerModule;

/**
 * Created by lkm on 18/1/12.
 */

public class SteelyardServerModuleDelegateSerialport implements ModuleDelegate<SteelyardServerModule,Void>{

    private ModuleManager mModuleManager;
    @Override
    public void init(ModuleManager moduleManager) {
        mModuleManager=moduleManager;
    }

    @Override
    public void dependency(DependencyConfig dc) {
        dc.addDependency(SteelyardStatusManagerModule.class);
        dc.addDependency(SteelyardDataModule.class);

    }

    @Override
    public void configure(ConditionConfige<Void> cc) {
        cc.setPermissCondition(new PermissionCondition() {
            @Override
            public String[] initMissPermission() {
                return new String[]{
                        "android.permission.ACCESS_FINE_LOCATION"
//                        ,"android.permission.ACCESS_FINE_LOCATION"
                };
            }

            @Override
            public String[] initRunPermission() {
                return new String[0];
            }

            @Override
            public boolean isLazyRequestPermission() {
                return false;
            }
        });

    }

    @Override
    public SteelyardServerModule execute(Void aVoid) {
        SteelyardStatusManagerModule steelyardStatusManagerModule=(SteelyardStatusManagerModule)mModuleManager.loadModule(SteelyardStatusManagerModule.class);
        return new SteelyardServerModuleSerialport(steelyardStatusManagerModule);
    }

    @Override
    public Class<SteelyardServerModule> getModuleInterfaceClass() {
        return SteelyardServerModule.class;
    }

    @Override
    public void onError(ErrorWarp e) {

    }
}
